package cn.usian.service.impl;

import cn.usian.dao.EmpMapper;
import cn.usian.pojo.Emp;
import cn.usian.service.EmpService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class EmpServiceImpl implements EmpService {
    @Resource
    private EmpMapper empMapper;
    @Override
    public Page<Emp> findPage(Integer pageIndex,String name) {
        LambdaQueryWrapper<Emp> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(name!=null,Emp::getName,name);
        Page<Emp> page = new Page<>(pageIndex,2);
        Page<Emp> empPage = empMapper.selectPage(page, queryWrapper);
        return empPage;
    }

    @Override
    public void add(Emp emp) {
        empMapper.insert(emp);
    }

    @Override
    public void del(long id) {
        empMapper.deleteById(id);
    }
}
